package com.example.haojiutao.controller.user;

import com.example.haojiutao.common.Result;
import com.example.haojiutao.model.domain.Message;
import com.example.haojiutao.service.MessageService;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @Description: 消息控制层
 * @Author: wang_meiying
 * @CreateTime: 2024/1/22 19:25
 */
@Slf4j
@RestController

public class MessageController {
      @Autowired
     private MessageService messageService;

     /*
      * @Description: 接受消息
      * @Author: wang_meiying
      * @CreateTime: 2024/1/22 19:26
      * @param: message
      * @return: com.example.treasure_box.common.Result
      **/
     @PostMapping("messages")
     public Result addmessage(@RequestBody Message message) {

          log.info("联系商家",message);

          return messageService.insertMessage(message);
     }
     /*
      * @Description: 根据用户id删除消息
      * @Author: wang_meiying
      * @CreateTime: 2024/1/22 19:30
      * @param: id
      * @return: int
      **/
     @DeleteMapping("message")
     public int deleteMessage(int id){
          return messageService.deleteMessage(id);
     }

     @DeleteMapping("message/{id}")
     public int deleteMessage1(@PathVariable("id") int id){

          return messageService.deleteMessage(id);
     }
     /*
      * @Description: 查看消息
      * @Author: wang_meiying
      * @CreateTime: 2024/1/22 19:31
      * @param: message
      * @return: com.example.treasure_box.common.Result
      **/
     @GetMapping("/message/list")
     public Result selectbylist(Message message){
          log.info("列表查询参数 ：{}" ,message);
          List<Message> messages =messageService.selectMessage(message);
          PageInfo<Message> pageInfo=new PageInfo<>(messages);
          return Result.success("查询成功",messages);
     }

     /*
      * @Description: 根据用户id查看消息
      * @Author: wang_meiying
      * @CreateTime: 2024/1/22 19:32
      * @param: message
      * @return: com.example.treasure_box.common.Result
      **/
     @GetMapping("/message/{userId}")
     public int selectByUserId(@PathVariable("userId") int userId){

         // message.setUserId(4);
          return messageService.selectByUserId(userId);
     }

}
